const { DataTypes } = require("sequelize");

const Information = require("./information.model");
const Category = require("./category.model");
const seq = require("../db/seq");

// 创建模型(Model zd_user -> 表 zd_users)
const Middle = seq.define(
  "middle",
  {
    // id 会被sequelize自动创建, 管理
    comment_id: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "评论id",
    },
    infomation_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "资讯id",
    },
    category_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "项目id",
    },
  },
  {
    paranoid: true,
  }
);
Middle.belongsTo(Information, {
  foreignKey: "infomation_id",
  as: "infomation_info",
});
Middle.belongsTo(Category, {
  foreignKey: "category_id",
  as: "category_info",
});
// 强制同步数据库(创建数据表)
// Middle.sync({ force: true });

module.exports = Middle;
